package com.ebs.md.fxmonitor.marketmonitor.model;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/model/OBCNew.java $
 *  $Revision: #16 $  $Change: 115868 $  $DateTime: 2012/10/17 13:08:52 $  $Author: Arik.Sher $
 */

import com.ebs.md.api.BookSide;
import com.ebs.md.api.IDetailedBookEntry;
import com.ebs.md.api.Rate;
import com.ebs.md.api.orderbook.BookEntryPosition;
import com.ebs.md.api.product.PairProduct;

/**
 * OBCNew - OrderBookChange New entry (quote)
 * 
 * @author asher
 */
public class OBCNew
extends AbsOBChange
{
	// gened with Eclipse
	private static final long serialVersionUID = 6636478578440519140L;

	/**
	 * pipsDiffFromBest.
	 * 
	 * value of  0 means at top.
	 * value of  2 means two   pips above best(previous best, now i'm the best)
	 * value of -3 means three pips below the best.
	 * 
	 * note: pips (in this case) is "number of price increments"
	 */
	protected int pipsDiffFromBest;
	/**
	 * toppedQuoteId - quote id of the nearest lower rate.
	 * if this new quote the at Best/Top than the ToppedQuoteId is previous quote of the best.
	 * if no rates(quote) below, then value is null.
	 * if not the first entry at price level(position) than value will be null.
	 * 
	 * note: might be multiple ids, currently holding only one id (top(came first) at price level)
	 */
	protected String toppedQuoteId = null;

	// using the BookEntryPosition for methods convenience
	protected BookEntryPosition bep;
	
	public OBCNew(long timestamp, String quoteId, PairProduct pair
			, BookSide bookSide, String dealCode, String traderId, Rate rate
			, long availAmount, int obPosition, int obEnriesAtPosition
			, int pipsDiffFromBest, String toppedQuoteId
			, long totalAmount, long displayAmount, String region, int firmId
	) {
		super(timestamp, quoteId, pair, bookSide, dealCode, traderId, rate, availAmount, obPosition, obEnriesAtPosition
			, totalAmount, displayAmount, region, firmId
			);
		this.pipsDiffFromBest = pipsDiffFromBest;
		this.toppedQuoteId    = toppedQuoteId;
		
		this.bep = new BookEntryPosition(obPosition, obEnriesAtPosition, 9876543);
	}

	public OBCNew(long timestamp, String quoteId, PairProduct pair
			, BookSide bookSide, String dealCode, String traderId, Rate rate
			, long availAmount, int obPosition, int obEnriesAtPosition
			, int pipsDiffFromBest, String toppedQuoteId
			, long totalAmount, String region, int firmId
	) {
		this(timestamp, quoteId, pair, bookSide, dealCode, traderId, rate
				, availAmount, obPosition, obEnriesAtPosition
				, pipsDiffFromBest, toppedQuoteId
				, totalAmount, availAmount, region, firmId
		);
	}
	
	public OBCNew(long timestamp, String quoteId, PairProduct pair
			, BookSide bookSide, String dealCode, String traderId, Rate rate
			, long availAmount, int obPosition, int obEnriesAtPosition
			, int pipsDiffFromBest, String toppedQuoteId, String region, int firmId
	) {
		this(timestamp, quoteId, pair, bookSide, dealCode, traderId, rate
				, availAmount, obPosition, obEnriesAtPosition
				, pipsDiffFromBest, toppedQuoteId
				, availAmount, availAmount, region, firmId
			);
	}

	public OBCNew(PairProduct pair, IDetailedBookEntry be, BookEntryPosition bep, int firmId
			, int pipsDiffFromBest, String toppedQuoteId) {
		super(pair, be, bep, firmId);
		this.pipsDiffFromBest = pipsDiffFromBest;
		this.toppedQuoteId    = toppedQuoteId;
		
		this.bep = bep;
	}

	public int getPipsDiffFromBest() {
		return pipsDiffFromBest;
	}

	public String getToppedQuoteId() {
		return toppedQuoteId;
	}

	public boolean isObNewPosition() {
		return bep.isNewPosition();
	}
	
	public boolean isObNewBest() {
		return bep.isTOBchange();
	}

	public boolean isAtTopOfBook() {
		return bep.isTop();
	}
	
	protected String additionalFields4toString() {
		return ", pipsDiffFromBest=" + pipsDiffFromBest
		     + ", toppedQuoteId=" + toppedQuoteId
		;
	}

}
